package com.example.steveaoblogdemo.controller;

import com.example.steveaoblogdemo.service.impl.ArticlesServiceImpl;
import com.example.steveaoblogdemo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
public class ArticlesController {

   @Resource
   ArticlesServiceImpl articlesService;

   @GetMapping("/articles/queryBlogs")
   public Result<?> query(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,@RequestParam(defaultValue = "") String search){
       return articlesService.queryBlog(pageNum,pageSize,search);
   }

   @PostMapping("/articles/addBlogs")
   public int add(@RequestParam(required = false) Integer id,@RequestParam(defaultValue = "") String author, @RequestParam(defaultValue = "") String title,  @RequestParam(defaultValue = "") String summarize,@RequestParam(defaultValue = "") String content ,@RequestParam(defaultValue = "") String tags, @RequestParam(defaultValue = "") String category, @RequestParam(defaultValue = "") String createTime){
      System.out.println(123);
      System.out.println("作者："+author+"标题： "+title+"概述： "+summarize+"标签： "+tags+"分类： "+category+
              "创建时间 "+createTime+"文章内容 "+content);
      return articlesService.addBlog(id,author,title,summarize,content,tags,category,createTime);
   }

   @GetMapping("/articles/queryBlogById")
   public Result<?> queryById(@RequestParam(required = false) Integer id){
      return articlesService.queryById(id);
   }

   @PutMapping("/articles/updateBlog")
   public int update(@RequestParam(defaultValue = "") String author, @RequestParam(defaultValue = "") String title, @RequestParam(defaultValue = "") String summarize,@RequestParam(defaultValue = "") String content ,@RequestParam(defaultValue = "") String tags, @RequestParam(defaultValue = "") String category, @RequestParam(defaultValue = "") String createTime,@RequestParam(required = false) Integer id){
      return articlesService.updateBlog(author,title,summarize,content,tags,category,createTime,id);
   }

   @PutMapping("/articles/deleteById")
   public Result<?> delete(@RequestParam(required = false) Integer id){
      return articlesService.deleteById(id);
   }

   @PutMapping("/articles/likeBlog")
   public Result<?> likeBlog(@RequestParam(required = false)Integer id,@RequestParam(required = false)Integer uid){
      return articlesService.likeBlog(id,uid);
   }
}
